﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Laos;

namespace Lisphi.Lab.PostSharpTests
{
    [Serializable]
    public class MyOnExceptionAspectAttribute : OnExceptionAspect
    {
        public override Type GetExceptionType(System.Reflection.MethodBase method)
        {
            return base.GetExceptionType(method);
        }

        public override void OnException(MethodExecutionEventArgs eventArgs)
        {
            //eventArgs.FlowBehavior = FlowBehavior.
            //base.OnException(eventArgs);
            Console.WriteLine("Exception occurs: " + eventArgs.Exception.ToString());
            eventArgs.FlowBehavior = FlowBehavior.Default;
        }
    }

    [Serializable]
    public class MyOnMethodBoundaryAspectAttribute : OnMethodBoundaryAspect 
    {
        public override Type GetExceptionType(System.Reflection.MethodBase method)
        {
            return base.GetExceptionType(method);
        }

        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            Console.WriteLine("Entry " + eventArgs.Method.DeclaringType.ToString());
        }

        public override void OnExit(MethodExecutionEventArgs eventArgs)
        {
            Console.WriteLine("Exit " + eventArgs.Method.DeclaringType.ToString());
        }

        public override void OnSuccess(MethodExecutionEventArgs eventArgs)
        {
            Console.WriteLine("Success " + eventArgs.Method.DeclaringType.ToString());
        }

        public override void OnException(MethodExecutionEventArgs eventArgs)
        {
            Console.WriteLine("Exception " + eventArgs.Exception.ToString());
        }
    }

    [Serializable]
    public class MyOnMethodInvocationAspectAttribute : OnMethodInvocationAspect
    {
        public override void OnInvocation(MethodInvocationEventArgs eventArgs)
        {
            Console.WriteLine("OnInvocation...");
        }
    }

    [Serializable]
    public class MyOnFieldAccessAspectAttribute : OnFieldAccessAspect
    {
        public override void OnGetValue(FieldAccessEventArgs eventArgs)
        {
            eventArgs.StoredFieldValue = 101;
        }

        public override void OnSetValue(FieldAccessEventArgs eventArgs)
        {
            eventArgs.StoredFieldValue = 102;
        }
    }

    [Serializable]
    public class MyCompositionAspectAttribute : CompositionAspect
    {
        public override Type GetPublicInterface(Type containerType)
        {
            throw new NotImplementedException();
        }

        public override Type[] GetProtectedInterfaces(Type containerType)
        {
            return base.GetProtectedInterfaces(containerType);
        }

        public override object CreateImplementationObject(InstanceBoundLaosEventArgs eventArgs)
        {
            throw new NotImplementedException();
        }
    }

    [Serializable]
    public class MyImplementMethodAttribute : ImplementMethodAspect 
    {
        public override void OnExecution(MethodExecutionEventArgs eventArgs)
        {
            throw new NotImplementedException();
        }   
    }
}
